package cn.jsu.oj.judgment.config;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

@Configuration
public class JudgeThreadConfig {


    @Bean("judgeExecutor")
    ExecutorService initSubjectExecutorThreadPool() {
        LinkedBlockingQueue<Runnable> threadQueue = new LinkedBlockingQueue<>(1024);
        return new ThreadPoolExecutor(5, 10,
                500L, TimeUnit.MILLISECONDS,
                threadQueue);
    }


    @Bean("judgeSchedule")
    ScheduledThreadPoolExecutor initSubjectScheduleThreadPool() {
        ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("thread-call-runner-%d").build();
        return new ScheduledThreadPoolExecutor(5, threadFactory);
    }
}
